Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Globalization

#Region "CustomObject3"

<TypeConverter(GetType(CustomObject3Converter))> _
Public Class CustomObject3
  Private _X As Integer
  Private _Y As Integer

  Public Property X() As Integer
    Get
      Return _X
    End Get
    Set(ByVal value As Integer)
      _X = value
    End Set
  End Property

  Public Property Y() As Integer
    Get
      Return _Y
    End Get
    Set(ByVal value As Integer)
      _Y = value
    End Set
  End Property

  Public Sub New(ByVal x As Integer, ByVal y As Integer)
    _X = x
    _Y = y
  End Sub
End Class

#End Region 'CustomObject3

#Region "CustomObject3Converter"

Public Class CustomObject3Converter
  Inherits TypeConverter

  Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
    If sourceType Is GetType(String) Then
      Return True
    End If

    Return MyBase.CanConvertFrom(context, sourceType)
  End Function

  Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, _
    ByVal culture As CultureInfo, ByVal value As Object) As Object
    If TypeOf value Is String Then
      Dim values As String()

      values = CStr(value).Split(",")
      Return New CustomObject3(Integer.Parse(values(0)), Integer.Parse(values(1)))
    End If
    Return MyBase.ConvertFrom(context, culture, value)
  End Function

  Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, _
     ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
    If destinationType Is GetType(String) Then
      Return CType(value, CustomObject3).X & "," & CType(value, CustomObject3).Y
    End If
    Return MyBase.ConvertTo(context, culture, value, destinationType)
  End Function
End Class

#End Region 'CustomObject3Converter